<?php
// user.php --- Time-stamp: <2009-01-03 23:33:20 root>
// Copyright 2008 Julian Qian
// Author: lancer@pdn
// Version: $Id: login.php,v 0.0 2008/12/24 07:44:12 lancer Exp $
// Keywords: 

class User extends Model {
    var $_username;
    var $_uid;
    
    function User(){
        parent::Model();
    }

    function auth($username, $password){
        $sql = "select uid, passwd from user where username='$username' limit 1";
        $query = $this->db->query($sql);
        if($query->num_rows() > 0){
            $row = $query->row();

            $passwd = $row->passwd;

            if($passwd == md5($password)){
                $this->_uid = $row->uid;
                return true;
            }
        }
        return false;
    }

    function get_uid(){
        return $this->_uid;
    }

    function get_devids(){
        $uid = $this->_uid;
        $query = $this->db->query("select DISTINCT devid from phone where uid=$uid");
        $devids = array();
        foreach($query->result() as $row){
            array_push($devids, $row->devid);
        }
        return $devids;
    }

    function add_user($userinfo){
        $query = $this->db->query("insert into user ( username, passwd) values ('".$userinfo["username"]."','".$userinfo["password"]."');");
    }

    function all_user(){
        $query = $this->db->query("select * from user");
        return $query->result();
    }
  }

?>